package cn.utils;

import cn.dto.BizConstant;
import cn.hutool.crypto.digest.DigestUtil;
import cn.hutool.http.HttpRequest;

import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;
import java.util.concurrent.atomic.AtomicInteger;

public class GuideTable {


    private static  AtomicInteger deviceCount = new AtomicInteger();
    private static  String token =null;

    public static String getSessionId(BizConstant bizConstant) {

    if (token != null){
        return token;
    }

        String login_url = bizConstant.getLOGIN_URL();
        String wl_username = bizConstant.getWl_username();
        String lw_password = bizConstant.getLw_password();
        String md5 = MD5(lw_password);


        token = HttpRequest.get(login_url).form("loginName",wl_username).form("password",md5).execute().header("Authenticator");
        System.out.println("获取token次数"+deviceCount.incrementAndGet());
        return token;
      //  return "eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJ1c2VyQ29kZSI6InhvZ280ejhyYyIsInVzZXJOYW1lIjoic3lzXzE1MDAyODk2MzA1IiwicGhvbmUiOiIxNTAwMjg5NjMwNSIsInJlYWxOYW1lIjoi6ZmI6aOe6bi_IiwiZW1haWwiOiIxNTAwMjg5NjMwNUBxcS5jb20iLCJ1c2VyVHlwZSI6MSwib3JnSWQiOjE1LCJzaG9ydE5hbWUiOiIxNTAwMjg5NjMwNSIsImZ1bGxOYW1lIjoiMTUwMDI4OTYzMDUiLCJ1bmlJZCI6IjE1MDAyODk2MzA1IiwiY2hhcnRlclR5cGUiOiIzIiwidGltZSI6MTY1NzE4ODk5MjQ5MiwicmFuZG9tIjoiRlpDVFpuc25WNGJPRjY1XzMzS0U0In0.-Er7kljkpMAUyAwvc7gWowwnA0-zm-mb4CZ2KRzQ32U";
    }

    public static String MD5(String lw_password) {

        try {
            String md5 = DigestUtil.md5Hex(lw_password);
            return md5;
        } catch (Exception e) {
            e.printStackTrace();
            return null;
        }

    }
}
